package com.hl.web.fore;

import com.hl.pojo.Announcement;
import com.hl.pojo.ArticleCategory;
import com.hl.service.AnnouncementService;
import com.hl.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@RequestMapping("/announcement")
public class AnnouncementController {
    @Autowired
    private AnnouncementService announcementService;
    @PostMapping("/add")
    public ResultEntity add(@RequestBody Announcement announcement){
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        announcement.setPublishTime(simpleDateFormat.format(date));
        announcementService.add(announcement);
        return ResultEntity.ok("发布成功");
    }

    @GetMapping("/del")
    public ResultEntity del( Integer id){
        announcementService.del(id);
        return ResultEntity.ok("删除成功");
    }
    @GetMapping("/findAll")
    public ResultEntity findAll(Announcement announcement){
        return ResultEntity.ok(announcementService.findAll(announcement));
    }
   @PostMapping("/update")
    public ResultEntity update(@RequestBody Announcement announcement){
        announcementService.update(announcement );
        return ResultEntity.ok("修改成功");
    }
    @GetMapping("/findAll2")
    public ResultEntity findAll2(String name){
        return ResultEntity.ok(announcementService.findAll2(name));
    }

}
